import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 */
public class Test2 {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i < n; i++) {
            char tmp = A.charAt(i);
            if(tmp == '(') {
                stack.push(tmp);
            }else if(tmp == ')'){
                if(!stack.empty()) {
                    stack.pop();
                }else {
                    return false;
                }
            }else {
                return false;
            }
        }
        if(!stack.empty()) {
            return false;
        }
        return true;
    }
}
